import * as mongoose from 'mongoose';
import db from './../core/mongodb';

/**
 * 菜单 实体类
 */
let menuSchema: mongoose.Schema = new mongoose.Schema(
    {
        name: String,  //名称
        icon: String, //小图
        img: String, //图片
        star: String, //平均评分 字符串类型 1 2 3 4 5
        sort: Number
    }, { collection: 'menu', timestamps: { createdAt: 'createDate', updatedAt: 'updateDate' } });
export interface Menu extends mongoose.Document {
    name: string;
    icon: string;
    img: string;
    star: string;
    sort: number;
}

export let menuModel = db.model<Menu>('menu', menuSchema);


/**
 * 用户打分 实体类
 */
let starSchema: mongoose.Schema = new mongoose.Schema(
    {
        openId: String, //用户唯一标识
        star: Number,//用户评分 字符串类型 1 2 3 4 5
        invalid: String, //失效时间
        menuId: String // 菜单表主键
    }, { collection: 'star', timestamps: { createdAt: 'createDate', updatedAt: 'updateDate' } });
export interface Star extends mongoose.Document {
    openId: string;
    star: number;
    invalid: string;
    menuId: string;
}

export let starModel = db.model<Star>('star', starSchema);